export default{
	namespaced:true,
	state:()=>({
		cart:JSON.parse(uni.getStorageSync('cart')||'[]')
	}),
	mutations:{
		addCart(state,product){
		const findResult= state.cart.find(x=>x.productId===product.productId)
		if(!findResult){
			state.cart.push(product)
		}else{
			findResult.num++
		}
		this.commit('m_cart/savetoStorage')
		}
	},
    savetoStorage(state){
		uni.setStorageSync('cart',JSON.stringify(state.cart))
	}
	updateGoodsState(state,product){
	const findResult=state.cart.find(x => x.id===product.id)
	if(findResult){
		findResult.check=product.check
		this.commit('m_cart/savetoStorage')
	}
	}
}